home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / tacmwino / wavemain.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-07-19  |  4.1 KB  |  167 lines

  1. Unit WaveMain;
  2.  
  3. Interface
  4.  
  5. Uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, mmsystem, ACMWaveIO, ExtCtrls, Buttons;
  8.  
  9. Type
  10.   TForm1 = Class(TForm)
  11.     WaveIN1: TACMWaveIN;
  12.     WaveOut1: TACMWaveOut;
  13.     Panel1: TPanel;
  14.     PaintBox1: TPaintBox;
  15.     Panel2: TPanel;
  16.     StartBtn: TButton;
  17.     StopBtn: TButton;
  18.     CloseBtn: TButton;
  19.     SpeedButton1: TSpeedButton;
  20.     Procedure StartBtnClick(Sender: TObject);
  21.     Procedure StopBtnClick(Sender: TObject);
  22.     Procedure WaveIn1Data(Sender: TObject; Data: PChar; Size: Integer);
  23.     Procedure CloseBtnClick(Sender: TObject);
  24.     Procedure WaveFormatClick(Sender: TObject);
  25.     Procedure FormClose(Sender: TObject; Var Action: TCloseAction);
  26.     Procedure WaveIN1Open(Sender: TObject);
  27.     Procedure WaveIN1Close(Sender: TObject);
  28.   PRIVATE
  29.           { Private declarations }
  30.   PUBLIC
  31.           { Public declarations }
  32.     Tick: Integer;
  33.   End;
  34.  
  35. Const
  36.   FormCaption: String = 'ACM Codec Wave Sample';
  37.  
  38. Var
  39.   Form1: TForm1;
  40.  
  41. Implementation
  42.  
  43. {$R *.DFM}
  44.  
  45. Procedure TForm1.StartBtnClick(Sender: TObject);
  46. Begin
  47.   Tick := -1;
  48.  
  49.   WaveOut1.WaveFormat.Assign(WaveIn1.WaveFormat);
  50.  
  51.   WaveIN1.OPEN;
  52.   WaveOut1.OPEN;
  53.  
  54.   StartBtn.Enabled := False;
  55.   StopBtn.Enabled := True;
  56. End;
  57.  
  58. Procedure TForm1.StopBtnClick(Sender: TObject);
  59. Begin
  60.   WaveIN1.CLOSE;
  61.   WaveOut1.CLOSE;
  62.  
  63.   StartBtn.Enabled := True;
  64.   StopBtn.Enabled := False;
  65. End;
  66.  
  67. Procedure TForm1.WaveIn1Data(Sender: TObject; Data: PChar; Size: Integer);
  68. Var
  69.   DC: HDC;
  70.   R: TRect;
  71.   P, S: Single;
  72.   I: Integer;
  73.   V: SmallInt;
  74. Begin
  75.   PaintBox1.Canvas.Font.COLOR := clWhite;
  76.   PaintBox1.Canvas.Font.Size := 14;
  77.  
  78.   If WaveIN1.WaveFormat.WaveFormat^.wFormatTag = WAVE_FORMAT_PCM Then
  79.     Begin
  80.       PaintBox1.Canvas.Pen.COLOR := clYellow;
  81.       PaintBox1.Canvas.BRUSH.Style := bsSolid;
  82.       PaintBox1.Canvas.BRUSH.COLOR := clBlack;
  83.  
  84.       PaintBox1.Canvas.FillRect(PaintBox1.ClientRect);
  85.       DC := PaintBox1.Canvas.Handle;
  86.  
  87.       P := 0.0;
  88.  
  89.       Case WaveIN1.WaveFormat.WaveFormat^.wBitsPerSample Of
  90.         8:
  91.           Begin
  92.             S := Size / PaintBox1.Width;
  93.             MoveToEx(DC, 0, Byte(Data^) * PaintBox1.Height Div 255, Nil);
  94.             For I := 0 To PaintBox1.Width - 1 Do
  95.               Begin
  96.                 LineTo(DC, I, PByte(Longint(Data) + Trunc(P))^ * PaintBox1.Height Div 255);
  97.                 P := P + S;
  98.               End;
  99.           End;
  100.         16:
  101.           Begin
  102.             S := (Size Div 2) / PaintBox1.Width;
  103.             V := PSmallInt(Longint(Data))^;
  104.             MoveToEx(DC, 0, (PaintBox1.Height Div 2) - Trunc(V * PaintBox1.Height / 65535), Nil);
  105.             For I := 0 To PaintBox1.Width - 1 Do
  106.               Begin
  107.                 V := PSmallInt(Longint(Data) + Trunc(P) + Trunc(P) Mod 2)^;
  108.                 LineTo(DC, I, (PaintBox1.Height Div 2) - Trunc(V * PaintBox1.Height / 65535));
  109.                 P := P + S * 2;
  110.               End;
  111.           End;
  112.       End;
  113.     End Else
  114.     Begin
  115.       PaintBox1.Canvas.Brush.Color := clGray;
  116.       PaintBox1.Canvas.FillRect(PaintBox1.ClientRect);
  117.     End;
  118.  
  119.  
  120.   SetBkMode(PaintBox1.Canvas.Handle, TRANSPARENT);
  121.   R := PaintBox1.ClientRect;
  122.   If Tick >= 0 Then
  123.     DrawText(PaintBox1.Canvas.Handle, PChar(Format('%5.2f BPS', [1000 * Size / (GetTickCount - Tick + 1)])), -1,
  124.       R, DT_CENTER Or DT_VCENTER);
  125.   Tick := GetTickCount;
  126.  
  127.   WaveOut1.PlayBack(Data, Size);
  128. End;
  129.  
  130. Procedure TForm1.CloseBtnClick(Sender: TObject);
  131. Begin
  132.   CLOSE;
  133. End;
  134.  
  135. Procedure TForm1.WaveFormatClick(Sender: TObject);
  136. Begin
  137.   If (WaveIn1.Active) Or (WaveOut1.Active) Then
  138.     Begin
  139.       ShowMessage('Cannot change wave format when active !');
  140.       Exit;
  141.     End;
  142.  
  143.   WaveIN1.WaveFormat.Execute;
  144.   WaveOut1.WaveFormat.Assign(WaveIn1.WaveFormat);
  145. End;
  146.  
  147. Procedure TForm1.FormClose(Sender: TObject; Var Action: TCloseAction);
  148. Begin
  149.   WaveIN1.CLOSE;
  150.   WaveOut1.CLOSE;
  151. End;
  152.  
  153. Procedure TForm1.WaveIN1Open(Sender: TObject);
  154. Begin
  155.   Caption := FormCaption + ' - [Active]';
  156. End;
  157.  
  158. Procedure TForm1.WaveIN1Close(Sender: TObject);
  159. Begin
  160.   Caption := FormCaption + ' - [Inactive]';
  161. End;
  162.  
  163.  
  164.  
  165. End.
  166.  
  167.